package service.impl;

import dao.WareHouseProductDao;
import dao.impl.WareHouseProductDaoImpl;
import entity.Warehouse_Product;
import service.WarehouseProductService;

public class WarehouseProductServiceImpl implements WarehouseProductService{
	private WareHouseProductDao wpd = new WareHouseProductDaoImpl();
	@Override
	public Integer queryWarehouseProductIdByProductIdAndModelId(Integer productId, Integer modelId) {
		return wpd.queryWarehouseProductIdByProductIdAndModelId(productId, modelId);
	}

	@Override
	public boolean productIsEnoughByIdAndNeed(Integer wp_id, Integer need) {
		Warehouse_Product wp = wpd.queryWarehouse_ProductById(wp_id);
		if(wp!=null&&wp.getCurrent_cnt()>=need){
			return true;
		}
		return false;
	}

	@Override
	public boolean updateWarehouse_ProductByIdAndNeed(Integer wp_id, Integer need) {
		//修改之前先判断是否该产品是否满足修改的要求
		boolean flag = this.productIsEnoughByIdAndNeed(wp_id, need);
		boolean result = false;
		if(flag){
			//如果满足就去修改
			int i = wpd.updateWarehouse_ProductByIdAndCount(wp_id, need);
			if(i==1){
				return true;
			}
		}
		return result;
	}

}
